﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PocketEngine.Maths;
using FarseerGames.FarseerPhysics;
using FarseerGames.FarseerPhysics.Dynamics;
using FarseerGames.FarseerPhysics.Factories;
namespace PocketEngine.Physics
{
    public class pBody
    {
        public Body Body
        {
            get
            {
                return mBody;
            }
            set
            {
                mBody = value;
            }
        }
        private Body mBody = null;
        public pGeom Geom
        {
            get
            {
                return mGeom;
            }
            set
            {
                mGeom = value;
            }
        }
        private pGeom mGeom = null;
        public pVec2 Position
        {
            get
            {
                return new pVec2(Body.Position.X, Body.Position.Y);
            }
            set
            {
                Body.Position = new FarseerGames.FarseerPhysics.Mathematics.Vector2(value.X, value.Y);
            }
        }

        public float Rotation
        {
            get
            {
                return Body.Rotation;
            }
            set
            {
                Body.Rotation = value;
            }
        }

        public void Impulse(pVec2 imp)
        {
            Body.ApplyImpulse(new FarseerGames.FarseerPhysics.Mathematics.Vector2(imp.X, imp.Y));
        }
        public enum BodySpace
        {
            Local,World
        }
        public void ForceAtPos(pVec2 pos, pVec2 imp, BodySpace space)
        {
            if (space == BodySpace.Local)
            {
                Body.ApplyForceAtLocalPoint(new FarseerGames.FarseerPhysics.Mathematics.Vector2(imp.X, imp.Y), new FarseerGames.FarseerPhysics.Mathematics.Vector2(pos.X, pos.Y));
            }
            else
            {
                Body.ApplyForceAtWorldPoint(new FarseerGames.FarseerPhysics.Mathematics.Vector2(imp.X, imp.Y), new FarseerGames.FarseerPhysics.Mathematics.Vector2(pos.X, pos.Y));
            }
        }
        public void TurnTorque(float force)
        {
            Body.ApplyTorque(force);
        }
        public void TurnImpulse(float force)
        {
            Body.ApplyAngularImpulse(force);    
        }

        public pBody()
        {
           
        }

        public virtual void Update()
        {
        }
       
    }
}
